package com.xxd.spring.boot.demo.wubolin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxd.spring.boot.demo.wubolin.Result;
import com.xxd.spring.boot.demo.wubolin.entity.Grade;
import com.xxd.spring.boot.demo.wubolin.exception.MyException;
import com.xxd.spring.boot.demo.wubolin.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/grade")
public class GradeController {
    @Autowired
    private GradeService gradeService;

    @RequestMapping("/add")
    public Result add(@RequestBody Grade grade) throws MyException {
        gradeService.add(grade);
        return new Result().success();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Grade grade) throws MyException {
        gradeService.update(grade);
        return new Result().success();
    }

    @RequestMapping("/delete{id}")
    public Result detele(@PathVariable Integer id) throws MyException {
        gradeService.delete(id);
        return new Result().success();
    }

    @RequestMapping("/listPage")
    public Result listPage(Page page, @RequestParam Map<String,Object> params) throws MyException {
        IPage resPage = gradeService.listPage(page,params);
        return new Result().success().setData(resPage);
    }

    @RequestMapping("/list")
    public Result list(@RequestBody Map<String,Object> params) throws MyException {
        List<Grade> list = gradeService.list(params);
        return new Result().success().setData(list);
    }

    @RequestMapping("/info/{code}")
    public Result list(@PathVariable("code") String code ) throws MyException {
        Grade list = gradeService.infoByCode(code);
        return new Result().success().setData(list);
    }

    @RequestMapping("/all")
    public Result all(){
        List<Grade> list = gradeService.all();
        return new Result().success().setData(list);
    }
}
